﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SharingCenter.Web.Classes;
using SharingCenter.Web.Classes.Events;
using SharingCenter.Web.Classes.Message;

namespace SharingCenter.Web.Mod.Events
{
    public partial class Invite : EventPageBase
    {
        Guid eventId = Guid.Empty;
        bool isParticipant = false;
        protected Sc_Event curEvent;
        protected void Page_Init(object sender, EventArgs e)
        {
            if (Request.QueryString["id"] == null)
            {
                Response.Redirect("~/");
            }
            else
            {
                eventId = new Guid(Request.QueryString["id"]);
                curEvent = EventOperations.GetEventFromEvnetId(eventId);
                using (scDataContext cxt = new scDataContext())
                {
                    isParticipant = Convert.ToBoolean(cxt.IsUserEventParticipant(Profile.UserId, eventId));
                }
                
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (curEvent != null)
            {
                Sc_MailTemplate tmp = MailOperations.GetMailTemplate("Events", "EventInviteTemplate");

                Dictionary<string, string> mailReplacement = new Dictionary<string, string>();
                mailReplacement.Add("NickName", Profile.Personal.NickName);
                mailReplacement.Add("Title", curEvent.Title);
                mailReplacement.Add("StartDate", curEvent.StartDate.ToString());
                mailReplacement.Add("EndDate", curEvent.EndDate.ToString());
                mailReplacement.Add("SignUpDeadline", curEvent.SignUpCloseDate.ToString());
                mailReplacement.Add("EventLink", string.Format("{0}/Mod/Events/View.aspx?id={1}", WebConsts.SITE_URL, eventId.ToString()));
                string title = tmp.MailSubject, cont = tmp.MailContent;
                MailOperations.GetReplacedContent(ref cont, ref title, mailReplacement);

                GetContactsAndSendMail1.MailSubject = title;
                GetContactsAndSendMail1.FixedMailContent = cont;

                GetContactsAndSendMail1.EntityType = curEvent.EventSource;
                GetContactsAndSendMail1.ContextId = eventId;
                GetContactsAndSendMail1.ReturnUrl = "~/Mod/Events/View.aspx?id=" + eventId.ToString();
            }
        }
    }
}
